class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int newsize=nums.size();
        int min=0;
        int ans=INT_MIN;
        int num=0;
        for(int i=0;i<newsize;++i){
            num+=nums[i];
            ans=max(ans,num-min);
            if(num<min){
                min=num;
            }
        }
        return ans;
    }
};